package com.ecommerce.dal.common;

import java.util.List;

import com.ecommerce.dal.entity.Communication;
import com.ecommerce.dal.entity.User;
import com.ecommerce.dal.entity.UserCommunication;
import com.ecommerce.dal.entity.UserCommunicationId;
import com.ecommerce.dal.service.impl.CommunicationManagementService;
import com.ecommerce.dal.service.impl.CommunicationManagerService;
import com.ecommerce.dal.service.impl.UserManagerService;

public class TestUserCommunication {

	public TestUserCommunication(
			CommunicationManagementService communicationManagementService,
			UserManagerService userManagerService,
			CommunicationManagerService communicationManagerService) {
		User user = userManagerService.retrieveUser(1);
		Communication communication = communicationManagerService
				.retrieveCommunication(1);

		UserCommunication userCommunication = new UserCommunication();
		UserCommunicationId userCommunicationId = new UserCommunicationId();

		userCommunication.setCommunication(communication);
		userCommunication.setUser(user);

		/** Building a UserCommunicationId Compound Key! */
		userCommunicationId.setCommunicationId(communication
				.getCommunicationId());
		userCommunicationId.setUserId(user.getUserId());
		userCommunicationId.setUserCommunicationDesc("01224205792");

		userCommunication.setId(userCommunicationId);

		System.out.println("Saving User: " + user.getFirstName()
				+ " With Communication Type: "
				+ communication.getCommunicationType());
		communicationManagementService.saveUserCommunication(userCommunication);

		System.out.println("Save complete");

		List<UserCommunication> userCommunicationList = communicationManagementService
				.retrieveAllUserCommunication("belal1");
		for (UserCommunication userCommunicationX : userCommunicationList) {
			System.out.println("User Name: "
					+ userCommunicationX.getUser().getUserName()
					+ " , and Communication Type is: "
					+ userCommunicationX.getCommunication()
							.getCommunicationType()
					+ " , User Communication Description: "
					+ userCommunicationX.getId().getUserCommunicationDesc());

		}

	}

}
